/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils.observer.entity;

import java.util.ArrayList;
import utils.observer.Observer;
import utils.observer.Subject;

/**
 *
 * @author Oliver Kraemer
 */
public class EntitySubject implements Subject {

    private ArrayList<Observer> observers;

    public EntitySubject() {
        observers = new ArrayList<>();
    }
    
    @Override
    public void notifyObservers() {
        for(Observer o: this.observers){
            o.update();
        }
    }

    @Override
    public void registerObserver(Observer o) {
        for (Observer observer : observers) {
            if ( observer.getClass().getName().equals(o.getClass().getName()) ) {
                return;
            }
        }

        this.observers.add(o);
    }

    @Override
    public void removeObserver(Observer o) {
        this.observers.remove(o);
    }

}
